import axios from '@/utils/request'
const ORDER_STATUS = {
  '-2': '支付失败',
  '-1': '已取消',
  0: '未支付',
  1: '已支付报名费用',
  2: '已结算'
}
const STATUS_COLOR = {
  '-2': 'danger',
  '-1': 'info',
  0: 'info',
  1: 'success',
  2: 'warning'
}
export default {
  ActivityRecord: {
    list: {
      export: {
        query: {
          '@display': `{
            'activity': 'entity.getActivity().getTitle()',
            'name': 'entity.getName()',
            'mobile': 'entity.getMobile()',
            'description': 'entity.getDescription()',
            'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")',
            'payStatus': 'entity.getInvoice().getStatus() == 1 ? "已支付" : "未支付"'
          }`,
          limit: 10000000
        },
        label: {
          'activity': '活动',
          'name': '姓名',
          'mobile': '电话',
          'description': '身份证',
          'createdTime': '报名时间',
          'payStatus': '支付状态'
        }
      },
      disabled_actions: ['new'],
      query: {
        '@order': `entity.id|DESC`
      },
      list_filter: {
        'activity.id': () => {
          return axios
            .get(`/manage/activities`)
            .then(res =>
              Object.assign({ __label: '活动' },
                ...res.data.map(v => { return { [v.id]: v.title } })))
        }
      },
      list_display: [
        'id',
        'invoice',
        {
          property: 'activity',
          label: '活动'
        },
        {
          property: 'name',
          label: '姓名'
        },
        {
          property: 'mobile',
          label: '电话'
        },
        {
          property: 'description',
          label: '身份证号',
          editAbled: true
        },
        {
          property: 'createdTime',
          label: '报名时间'
        },
        {
          property: 'status',
          label: '订单状态',
          component: {
            props: ['data'],
            data() {
              return {
                status: ORDER_STATUS,
                color: STATUS_COLOR,
                show: false,
                settleItems: []
              }
            },
            render(h) {
              return <div>
                <el-tag type={this.color[this.data]} effect='plain'>{this.status[this.data]}</el-tag>
              </div>
            }
          }
        }
      ]
    },
    form: {
      fields: [
        'name',
        'mobile',
        'description'
      ]
    }
  }
}

